//
//  RegisteredVC.m
//  豆瓣
//
//  Created by lanou3g on 15/12/9.
//  Copyright © 2015年 HaiTeng. All rights reserved.
//

#import "RegisteredVC.h"

@interface RegisteredVC ()

@end

@implementation RegisteredVC


- (void)loadView
{
    self.registeredView = [[RegisteredView alloc] init];
    self.registeredView.scrollEnabled = YES;
    self.view = self.registeredView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"注册";
    [self setrightBarButton];
}

#pragma mark 设置注册按钮
- (void)setrightBarButton
{
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarAction:)];
    
    
}

- (void)rightBarAction:(UIBarButtonItem *)sender
{

    
    //用户名和密码不为空, 并且 密码,和重复密码一致
    if ([self.registeredView.nameTF.text isEqualToString:@""] || [self.registeredView.passwordTF.text isEqualToString:@""]) {
       
        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"用户名和密码不能为空" preferredStyle:UIAlertControllerStyleAlert];
        
        
        [alertC addAction:[UIAlertAction actionWithTitle:@"好吧" style:UIAlertActionStyleDestructive handler:nil]];
        
        
        [self presentViewController:alertC animated:YES completion:nil];
        
    }else if (![self.registeredView.passwordTF.text isEqualToString:self.registeredView.passwordTFYES.text]){
        
        
        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"两次密码不一致" preferredStyle:UIAlertControllerStyleAlert];
        
        
        [alertC addAction:[UIAlertAction actionWithTitle:@"好吧" style:UIAlertActionStyleDestructive handler:nil]];
        
        
        [self presentViewController:alertC animated:YES completion:nil];
        
        
    }else{
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        [user setObject:self.registeredView.passwordTF.text forKey:@"userPassWord"];
        [user setObject:self.registeredView.nameTF.text forKey:@"userName"];
     
    };
    
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *passWord = [ user objectForKey:@"userPassWord"];
    NSString *name = [user objectForKey:@"userName"];
    
        if (([passWord isEqualToString:@""] || passWord == nil)&& ([name isEqualToString:@""] || name == nil)) {
            
            
            NSLog(@"NO NO NO !!!");
        }else{
            
            
            UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"注册成功" preferredStyle:UIAlertControllerStyleAlert];
            
            
            [alertC addAction:[UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
                
                [self.navigationController popViewControllerAnimated:YES];
                
            }]];
            
            
            [self presentViewController:alertC animated:YES completion:nil];
            
            
        }
        
        

    
    

    
}




@end
